#include <iostream>
#include <stdio.h>

#include <iostream>
#include <memory>
#include <vector>

using  namespace std;

class Solution
{
private:
    /* data */
public:
    vector<vector<int>> generateMatrix(int n){
        vector<vector<int>> res(n,vector<int>(n,0));
        int loop = n/2;
        int count = 1;
        int mid = n/2;
        int offset = 1;

        int start_x = 0;
        int start_y = 0;

        int x, y;

        while(loop --){

            x = start_x;
            y = start_y;
            
            for(y = start_y; y < start_y + n - offset; y++){
                res[start_x][y] = count++;
            }

            for(x = start_x; x < start_x + n -offset; x++){
                res[x][y] = count++;
            }

            for(; y > start_y; y--){
                res[x][y] = count++;
            }

            for(; x > start_x; x--){
                res[x][y] = count++;
            }



            start_x++;
            start_y++;
            offset +=2;
        }

        if(n % 2 != 0){
            res[mid][mid] = n*n;
        }

        return res;
    
    }
};





int main(int argv, char**argc)
{

    printf("************  test hello zc!!!   **************\n");
    /* add test code! */
    Solution solver;

    vector<vector<int>> nums = solver.generateMatrix(5);

    for(int i = 0; i < nums.size(); i++){
        for(int j = 0; j < nums[i].size(); j++){
            printf(" %2d",nums[i][j]);
        }
        printf("\n");
    }

    return 0;
}
